package com.example.ywj.toutiao.utils;

import android.graphics.Typeface;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;

import com.example.ywj.toutiao.R;
import com.example.ywj.toutiao.bean.Lists;
import com.example.ywj.toutiao.bean.Set;

import java.util.List;

public class PopWindowAdapter1 extends BaseAdapter {
    private static final String TAG = "PopWindowAdapter1";
    public List<Lists> list;
    private String baseUrl = Constant.BASEURL;
    public PopWindowAdapter1(List<Lists> list){
        this.list = list;
    }
    @Override
    public int getCount() {
        Log.i(TAG, "getCount: "+list.size());
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder ;
        if(convertView == null) {
            LayoutInflater inflater = LayoutInflater.from(parent.getContext());
            convertView = inflater.inflate(R.layout.pop_item_layout, null);
            viewHolder = new ViewHolder();
            viewHolder.tv1 = convertView.findViewById(R.id.pop_item_textView1);
            viewHolder.tv2 = convertView.findViewById(R.id.pop_item_textView2);
            convertView.setTag(viewHolder);
        }else{
            viewHolder = (ViewHolder)convertView.getTag();
        }
        Log.i(TAG, "getView: "+list.get(position));
        viewHolder.tv2.setText(list.get(position).getContent());
        Typeface font = Typeface.createFromAsset(convertView.getContext().getAssets(), "iconfont.ttf");
        viewHolder.tv1.setTypeface(font);
        viewHolder.tv1.setText(convertView.getContext().getResources().getString(list.get(position).getPic()));
        return convertView;
    }
    class ViewHolder{
        TextView tv1;
        TextView tv2;
    }
}
